Skip to content

fix: parse MySQL mixed ADD COLUMN groups - #2930

Merged
manticore-projects merged 2 commits into
JSQLParser:masterfrom
minleejae:fix/mysql-add-column-table-elements-20261115
Nov 15, 2026
Merged

manticore-projects merged 2 commits into
JSQLParser:masterfrom
minleejae:fix/mysql-add-column-table-elements-20261115

Conversation

@minleejae

@minleejae minleejae commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

MySQL accepts columns, indexes and constraints together in a parenthesized ADD list,
but JSqlParser only read column definitions there:

ALTER TABLE t ADD COLUMN (
    a INT,
    CONSTRAINT ck CHECK (a > 0),
    b INT,
    KEY ix (b)
);

Preserve these declarations in source order as TableElement nodes. Reuse the existing
table-definition traversal and deparser so every CHECK/default expression, index and
foreign-key target remains accessible. Existing column-only groups retain their
representation; the column accessor stays mutable, and the singular constraint/index
accessors expose the first matching declaration in a mixed group.

The new grammar applies without a dialect or with Dialect.MYSQL. Regression coverage
includes constraints before columns, interleaved constraints and indexes, accessor
mutation, custom deparsing, visitors, validation and malformed groups.

References: MySQL ALTER TABLE,
server table_element_list grammar.

Validation:

  • The two original regression tests fail on master f880f35.
  • JDK 17 targeted tests: 25/25 PASS (the 19 new regressions and six table-element
    mutation tests). Checkstyle, SpotBugs, Spotless and JAR verification pass.
  • GitHub CI on b499a14: full Gradle Check passes on Linux, macOS and Windows;
    grammar ambiguity and Codacy pass. Maven Verify also passes on all three OSes.
  • Seven valid SQL cases parse, deparse and reparse with and without the MySQL dialect;
    all seven deparser outputs execute successfully on MySQL 8.4.13 with SHOW CREATE TABLE
    postchecks in isolated databases.
  • The SQL survey covers 80 DDL cases and two adjacent probes (164 observations
    across default/explicit dialect modes). It changes only the intended failing case and preserves previously parsed observations.

AI assistance: prepared with OpenAI Codex.

Preserve parenthesized ADD declarations in source order using existing
table-element models and traversal. Retain mutable column accessors and
visit/deparse every mixed column, constraint and index declaration.

Cover mixed order, constraints first, metadata validation, expression
visitors and compatibility with column-only groups.
Update the backing group list directly when replacing or removing its
first constraint or index. This preserves filtered-view semantics while
letting SpotBugs observe the mutation without a suppression.

Cover append when an element kind is absent and preservation of the
remaining declarations when the first constraint is removed.
@manticore-projects
manticore-projects merged commit ab3d9bb into JSQLParser:master Nov 15, 2026
10 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants